package com.community.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.community.entity.Parking;
import com.community.service.ParkingService;
import com.community.service.PlanService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("parking")
public class ParkingController extends ApiController {
    @Resource
    ParkingService parkingService;
    @Resource
    PlanService planService;

    @RequestMapping("parkinglist")
    public String parkinglist() {
        return "parkinglist";
    }

    @RequestMapping("list")
    @ResponseBody
    public R selectAll(Page<Parking> page, Parking parking) {
        QueryWrapper<Parking> wrapper = new QueryWrapper<>();
        wrapper.eq(parking.getCarState() != null, "car_state", parking.getCarState());
        wrapper.eq(parking.getPersonnelState() != null, "personnel_state", parking.getCarState());
        return success(this.parkingService.page(page, wrapper));
    }

    @RequestMapping("planlist")
    @ResponseBody
    public R planlist(Parking parking) {
        QueryWrapper<Parking> wrapper = new QueryWrapper<>();
        wrapper.eq(parking.getCarState() != null, "car_state", parking.getCarState());
        wrapper.eq(parking.getPersonnelState() != null, "personnel_state", parking.getCarState());
        return success(this.planService.selectAll());
    }

/*    @RequestMapping("count")
    @ResponseBody
    public R selctCount() {
        System.out.println("*******************count");
        return success(this.parkingService.count());
    }*/

    @GetMapping("count")
    @ResponseBody
    public R count(Parking parking) {
        QueryWrapper<Parking> wrapper = new QueryWrapper<>(parking);
        return success(this.parkingService.count(wrapper));
    }
}
